package com.cdut.logistics.action.businesses;

import java.util.Date;
import java.util.List;

import com.cdut.logistics.config.Constants;
import com.cdut.logistics.model.dao.datacentre.User;
import com.cdut.logistics.model.entity.Model.Repair_Order;
import com.cdut.logistics.service.Dto.RepairDto;
import com.cdut.logistics.service.impl.businesses.RepairServiceImp;
import com.cdut.logistics.service.interf.businesses.RepairService;
import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.cdut.logistics.intercepter.system.AuthorityIntercepter;
@Before(AuthorityIntercepter.class)
public class RepairController extends Controller {
	 RepairService repairService = new RepairServiceImp();
	
     public void index()
     {
    	 render("");
     }
     /**
      * 用户报修第一次异步调用的地方
      */
     //这里要添加拦截器，保证session 不为空
     public void repair_detail()
     {
    	 int user_id =2;// (Integer) this.getSession().getAttribute(Constants.User_SESSION);
    	 User user = repairService.user_detail(user_id);
    	 setAttr("user",user);
    	 
    	
    	 RepairDto repairDto = repairService.repair_detail(user_id);
    	 
    	 setAttr("repairDto",repairDto);
    	 renderJson();
    	 //查询学生学校信息
     }
     //这里要添加拦截器，保证session 不为空
     /*
      * 用户报修的记录创建
      */
     public void repair_create()
     {
    	 int user_id = 2;//(Integer) this.getSession().getAttribute(Constants.User_SESSION);
    	 int school_id = getParaToInt("school_id");
    	 int dorm_id = getParaToInt("dorm_id");
    	 int area_id = getParaToInt("area_id");
    	 int repair_type = getParaToInt("repair_type");
    	 String repair_text = getPara("repair_text");
    	 String img_url = "1";//getPara("img_url");
    	 String video_url = "2";//getPara("video_url");
    	 String remarks  = getPara("remarks");
    	 
    	 boolean is_success = repairService.repair_save(user_id,school_id, dorm_id, area_id, repair_type, repair_text, img_url, video_url, remarks);
    	 
    	 setAttr("is_success",is_success);
    	 renderJson();  	 
     }
     /**
      * 报修记录查询
      */
    //这里要添加拦截器，保证session 不为空
     public void repair_search()
     {
    	 int user_id = 2;//(Integer) this.getSession().getAttribute(Constants.User_SESSION);
    	 List<RepairDto> list = repairService.repairlist_detail(user_id);
    	 
    	 setAttr("list",list);
    	 renderJson();
     }
     /**
      *  单条报修记录查询
      */
     public void repair_single_detail()
     {
    	 int user_id = (Integer) this.getSession().getAttribute(Constants.User_SESSION);
    	 int order_id = getParaToInt("order_id");
    	 RepairDto repairDto = repairService.Repairsingle_detail(order_id, user_id);
    	 
    	 setAttr("repairDto",repairDto);
    	 renderJson();
     }
     /*
      * 取消订单
      */
     public void repair_cancel()
     {
    	 int order_id = getParaToInt("order_id");
    	 boolean is_success = repairService.repair_cancel(order_id);
    	 
    	 setAttr("is_success",is_success);
    	 renderJson();
     }
     /*
      * 维修任务
      */
     /**
      * 
      */
     public void repair_task()
     {
    	 //运营人员
    	 int user_id = (Integer) this.getSession().getAttribute(Constants.User_SESSION);
    	 int school_id  = getParaToInt("school_id");
    	 int area_id  = getParaToInt("area_id");
    	 String repair_member = getPara("repair_member");
    	 String start_time    =getPara("start_time"); 	
    	 String end_time    =getPara("end_time"); 	
    	 String remarks     = getPara("remarks"); 
    	 
    	 boolean is_success = repairService.repair_task(user_id, school_id, area_id, repair_member, start_time, end_time, remarks);
    	 setAttr("is_success",is_success);
    	 renderJson();
     }
     /**
      * 运维人员查询报修未审核记录
      */
      public void admin_repairlist_detail_baoxiu()
      {
          List<RepairDto> repairDto = repairService.admin_repairlist_detail_baoxiu();
     	 
     	 setAttr("repairDto",repairDto);
     	 renderJson();
      }
    /**
     * 运维人员查询报修未安排记录
     */
     public void admin_repairlist_detail()
     {
         List<RepairDto> repairDto = repairService.admin_repairlist_detail();
    	 
    	 setAttr("repairDto",repairDto);
    	 renderJson();
     }
     /**
      * 运维人员查询报修未调度记录
      */
      public void admin_repairlist_detail_diaodu()
      {
          List<RepairDto> repairDto = repairService.admin_repairlist_detail_diaodu();
     	 
     	 setAttr("repairDto",repairDto);
     	 renderJson();
      }
      /*
       * 查询已调度的报修记录
       */
      public void admin_repairlist_detail_result()
      {
    	  List<RepairDto> repairDto = repairService.admin_repairlist_detail_result();
      	 
      	 setAttr("repairDto",repairDto);
      	 renderJson();
      }
     /*
      * 运维人员查询单挑报修记录
      */
     public void admin_repairsingle_detail()
     {
    	 int order_id = getParaToInt("order_id");
    	 RepairDto repairDto = repairService.admin_Repairsingle_detail(order_id);
    	 
    	 setAttr("repairDto",repairDto);
    	 renderJson();
     }
     
     public void repair_auditing_agree()
     {
    	 int order_id = getParaToInt("order_id");
    	 boolean is_success = repairService.repair_auditing_agree(order_id);
    	 
    	 setAttr("is_success",is_success);
    	 renderJson();
     }
     
     public void repair_auditing_disagree()
     {
    	 int order_id = getParaToInt("order_id");
    	 String remarks = getPara("remarks");
    	 boolean is_success = repairService.repair_auditing_disagree(order_id,remarks);
    	 
    	 setAttr("is_success",is_success);
    	 renderJson();
     }
    
     public void repair_arrange()
     {
    	 int repair_leader = getParaToInt("repair_leader");
    	 int order_id = getParaToInt("order_id");
    	 
         boolean is_success = repairService.repair_arrange(order_id,repair_leader);
    	 
    	 setAttr("is_success",is_success);
    	 renderJson();
     }

     public void repair_diaodu()
     {
    	 String repair_member = getPara("repair_member");
    	 int order_id = getParaToInt("order_id");
    	 
         boolean is_success = repairService.repair_diaodu(order_id,repair_member);
    	 
    	 setAttr("is_success",is_success);
    	 renderJson();
     }
     /*
      * 查询
      */
     public void repair_result()
     {
    	 int order_id = getParaToInt("order_id");
    	 boolean is_success = repairService.repair_result(order_id);
    	 
    	 
    	 setAttr("is_success",is_success);
    	 renderJson();
     }
     
     public void repair_suggestion()
     {
    	 int user_id =2;// (Integer) this.getSession().getAttribute(Constants.User_SESSION);
    	 int order_id= getParaToInt("order_id");
    	 String content = getPara("content");
    	 
         boolean is_success = repairService.repair_suggestion(order_id, user_id, content);
    	 
    	 setAttr("is_success",is_success);
    	 renderJson();
     }
     
     public void repair_advice()
     {
    	 int user_id =2;// (Integer) this.getSession().getAttribute(Constants.User_SESSION);
    	 String content = getPara("content");
    	 
         boolean is_success = repairService.repair_advice(user_id, content);
    	 
    	 setAttr("is_success",is_success);
    	 renderJson();
     }
     
     /**
      * 查询未被安排的维修组长
      */
     
     public void repair_member_search()
     {
    	 String sql ="select * from user where role_id =2 and user_status=0  and "+Constants.sql_add;
    	 List<User> user = User.dao.find(sql);
    	 
    	 setAttr("list",user);
    	 renderJson();
     }
     
     public void repair_member1_search()
     {
    	 String sql ="select * from user where role_id =3 and user_status=0  and "+Constants.sql_add;
    	 List<User> user = User.dao.find(sql);
    	 
    	 setAttr("list",user);
    	 renderJson();
     }
}
